﻿using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Disposables;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ScienceAIApp.Views;
/// <summary>
/// Interaction logic for ImageContentView.xaml
/// </summary>
public partial class ImageContentView
{
    public ImageContentView()
    {
        InitializeComponent();
        this.WhenActivated(_activated);
    }

    void IsShowBigImageHandler(string flag)
    {
        this.Dispatcher.Invoke(new Action(() =>
        {
            if (flag.Contains("ax-true"))
            {
                Grid.SetRow(axcontainer, 1);
                Grid.SetColumn(axcontainer, 1);
                Grid.SetRowSpan(axcontainer, 3);
                Grid.SetColumnSpan(axcontainer, 3);
                sagcontainer.Visibility = Visibility.Collapsed;
                corcontainer.Visibility = Visibility.Collapsed;
                SplitLine1.Visibility = Visibility.Collapsed;
                SplitLine2.Visibility = Visibility.Collapsed;
                ThreeDContainer.Visibility = Visibility.Collapsed;
            }
            else if (flag.Contains("ax-false"))
            {
                Grid.SetRow(axcontainer, 1);
                Grid.SetColumn(axcontainer, 1);
                Grid.SetRowSpan(axcontainer, 1);
                Grid.SetColumnSpan(axcontainer, 1);
                sagcontainer.Visibility = Visibility.Visible;
                corcontainer.Visibility = Visibility.Visible;

                SplitLine1.Visibility = Visibility.Visible;
                SplitLine2.Visibility = Visibility.Visible;
                ThreeDContainer.Visibility = Visibility.Visible;
            }
            else if (flag.Contains("sag-true"))
            {
                Grid.SetRow(sagcontainer, 1);
                Grid.SetColumn(sagcontainer, 1);
                Grid.SetRowSpan(sagcontainer, 3);
                Grid.SetColumnSpan(sagcontainer, 3);
                axcontainer.Visibility = Visibility.Collapsed;
                corcontainer.Visibility = Visibility.Collapsed;

                SplitLine1.Visibility = Visibility.Collapsed;
                SplitLine2.Visibility = Visibility.Collapsed;
                ThreeDContainer.Visibility = Visibility.Collapsed;
            }
            else if (flag.Contains("sag-false"))
            {
                Grid.SetRow(sagcontainer, 1);
                Grid.SetColumn(sagcontainer, 3);
                Grid.SetRowSpan(sagcontainer, 1);
                Grid.SetColumnSpan(sagcontainer, 1);
                axcontainer.Visibility = Visibility.Visible;
                corcontainer.Visibility = Visibility.Visible;
                SplitLine1.Visibility = Visibility.Visible;
                SplitLine2.Visibility = Visibility.Visible;
                ThreeDContainer.Visibility = Visibility.Visible;
            }
            else if (flag.Contains("cor-true"))
            {
                Grid.SetRow(corcontainer, 1);
                Grid.SetColumn(corcontainer, 1);
                Grid.SetRowSpan(corcontainer, 3);
                Grid.SetColumnSpan(corcontainer, 3);
                axcontainer.Visibility = Visibility.Collapsed;
                sagcontainer.Visibility = Visibility.Collapsed;

                SplitLine1.Visibility = Visibility.Collapsed;
                SplitLine2.Visibility = Visibility.Collapsed;
                ThreeDContainer.Visibility = Visibility.Collapsed;
            }
            else if (flag.Contains("cor-false"))
            {
                Grid.SetRow(corcontainer, 3);
                Grid.SetColumn(corcontainer, 1);
                Grid.SetRowSpan(corcontainer, 1);
                Grid.SetColumnSpan(corcontainer, 1);
                axcontainer.Visibility = Visibility.Visible;
                sagcontainer.Visibility = Visibility.Visible;
                SplitLine1.Visibility = Visibility.Visible;
                SplitLine2.Visibility = Visibility.Visible;
                ThreeDContainer.Visibility = Visibility.Visible;
            }

        }));
    }

    private void _activated(CompositeDisposable disposable)
    {
        this.ViewModel!.IsShowBigImageEvent += IsShowBigImageHandler;

        this.OneWayBind(
                ViewModel,
                vm => vm.AxViewModel,
                v => v.AxViewHost.ViewModel)
            .DisposeWith(disposable);

        this.OneWayBind(
                ViewModel,
                vm => vm.SagViewModel,
                v => v.SagViewHost.ViewModel)
            .DisposeWith(disposable);

        this.OneWayBind(
                ViewModel,
                vm => vm.CorViewModel,
                v => v.CorViewHost.ViewModel)
            .DisposeWith(disposable);
    }
}
